<template>
   <div class="update-container">
          <div class="update-top-container">
              <el-page-header @back="goBack" content="商品页面">
              </el-page-header>
          </div>
      <el-form  ref="form" status-icon  :rules="rules" :model="form" label-width="80px">
        <el-form-item label="用戶名" prop="username">
          <el-input v-model="form.username" style="width:90%"></el-input>
        </el-form-item>
        
         <el-form-item label="密碼" prop="password">
          <el-input  v-model="form.password" style="width:90%"></el-input>
        </el-form-item>

        <el-form-item label="性別" prop="gender">
          <el-input  v-model="form.gender" style="width:90%"></el-input>
        </el-form-item>

        <el-form-item label="email" prop="email">
          <el-input  v-model="form.email" style="width:90%"></el-input>
        </el-form-item>

        <el-form-item label="introduction" prop="introduction">
          <el-input  v-model="form.introduction" style="width:90%"></el-input>
        </el-form-item>



        <div class="button-container">
          
            <el-button type="primary" @click="submit()" >提交</el-button>
          
        </div>
      </el-form>
    </div>
</template>

<script>
import {getCurrentTime} from '../util'
export default {
    name:'addUser',
    data() {
      return {
         choice:'新增用戶',
         IsOk:'',
         form: {
            username: '',
            password: '',
            gender:'',
            introduction:'',
            email:'',
            createTime:'',
            updateTime:'',

          },
         rules:{
          
         }
      
     }
    },
    methods: {
        async submit(){
          let that=this;
          //update....
          
         if(this.$route.query.do=='add'){
          //add
          console.log('add??');
          await this.$axios.get( "http://localhost:8081/addUser?"+
                               "username="+this.form.username+
                               "&password="+this.form.password+
                               "&gender="+this.form.gender+
                               "&email="+this.form.email+
                               "&introduction="+this.form.introduction+
                               "&createTime="+getCurrentTime()+
                               "&updateTime="+getCurrentTime()
                               
                               )
            .then((result) => {
                //console.log(result.data);
                that.$router.push({path:'/homepage/goodsInfo',query:{status:result.data}})
                return;
            }).catch((err) => {
              
            });
           }
          else
          {
           await this.$axios.get("http://localhost:8081/updateUser?"+
                               "&id="+this.$route.query.id+
                               "&username="+this.form.username+
                               "&password="+this.form.password+
                               "&email="+this.form.email+
                               "&introduction="+this.form.introduction+
                                "&gender="+this.form.gender+
                                "&updateTime="+getCurrentTime()
                                  )
                .then(result=>{
                     //console.log(result.data);
                that.$router.push({path:'/homepage/goodsInfo',query:{status:result.data}})
                })
  
          }
        },
        goBack(){
          this.$router.push('/homepage/goodsInfo');
        },
        load(){
          //console.log(this.$route);
          if(this.$route.query)
          {
            this.form.username=this.$route.query.username;
            this.form.password=this.$route.query.password;
            this.form.gender=this.$route.query.gender;
            this.form.email=this.$route.query.email;
            this.form.introduction=this.$route.query.introduction;
            this.form.createTime=this.$route.query.createTime;
            this.form.updateTime=this.$route.query.updateTime;
          }
        }
    },
    mounted() {
      this.load();
    },

}
</script>

<style>

   .el-form-item__content{
       width: 400px;
   }
   .update-container{
     width: 80%;
     padding: 20px;
     
   }
   .update-top-container{
     width: 100%;
     height: 50px;
     padding-left: 20px;
   }
</style>